<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="../assets/js/vue.js"></script>
    <title>methods Option</title>
</head>
<body>
<h1>methods Option</h1>
<hr>
<div id="app">
    {{ a }}
    <p>
        <button @click="add(2)">add</button>
    </p>
</div>

<script type="text/javascript">
    var app = new Vue({
        el: '#app',
        data: {
            a: 1
        },
        methods: {
            add: function (num) {
                if (num != '') {
                    this.a += num
                }
                else {
                    this.a++
                }
            }
        }
    })
</script>
</body>
</html>